package com.poisonh.unifiedauth.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.poisonh.unifiedauth.R;
import com.poisonh.unifiedauth.model.RecordModel;
import com.poisonh.unifiedauth.utils.ConstantUitls;

import net.karthikraj.shapesimage.ShapesImage;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by PoisonH on 2016/7/4.
 */
public class PtrrvAdapter extends PtrrvBaseAdapter<PtrrvAdapter.ViewHolder>
{
    private List<RecordModel> mListRecordModels;
    private Context mContext;

    public PtrrvAdapter(Context context)
    {
        super(context);
        this.mContext = context.getApplicationContext();
        mListRecordModels = new ArrayList<>();
    }

    @Override
    public int getItemCount()
    {
        return mListRecordModels.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        @SuppressLint("InflateParams")
        View view = mInflater.inflate(R.layout.ptrrv_item, null);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position)
    {
        holder.mTvAppName.setText(mListRecordModels.get(position).getNAME());
        holder.mTvTime.setText(mListRecordModels.get(position).getTIME());
//        if (mListRecordModels.get(position).getMARK().equals("0"))
//        {
//            holder.mIvState.setBackgroundResource(R.mipmap.dealwith_selected);
//        } else if (mListRecordModels.get(position).getMARK().equals("1"))
//        {
//            holder.mIvState.setBackgroundResource(R.mipmap.notdealwith_selected);
//        } else if (mListRecordModels.get(position).getMARK().equals("2"))
//        {
//            holder.mIvState.setBackgroundResource(R.mipmap.fail_selected);
//        }
        Glide.with(mContext).load(ConstantUitls.REQUEDT_IMG_URL + mListRecordModels.get(position).getC_IMGURL()).into(holder.mIvImg);
    }

    class ViewHolder extends RecyclerView.ViewHolder
    {
        private TextView mTvAppName;
        private TextView mTvTime;
        private ShapesImage mIvImg;
        // private ImageView mIvState;

        public ViewHolder(View view)
        {
            super(view);
            mTvAppName = (TextView) view.findViewById(R.id.tv_app_name);
            mTvTime = (TextView) view.findViewById(R.id.tv_time);
            mIvImg = (ShapesImage) view.findViewById(R.id.iv_app_img);
            //  mIvState = (ImageView) view.findViewById(R.id.iv_state);
        }
    }

    /**
     * 外部接口添加数据
     *
     * @param recordModels
     */
    public void setData(List<RecordModel> recordModels, boolean clean)
    {
        if (clean == false)
        {
            mListRecordModels.clear();
        }
        mListRecordModels.addAll(mListRecordModels.size(), recordModels);
        this.notifyDataSetChanged();
    }

    /**
     * 外部接口，清除数据
     */
    public void cleanData()
    {
        if (mListRecordModels.size() > 0)
        {
            mListRecordModels.clear();
        }
        this.notifyDataSetChanged();
    }
}
